package webx.actions;

import java.io.InputStream;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.xml.XmlConfiguration;

public class JettyServer {
    public static void start(){
    	try {
    	Server server = new Server();
		server.setHandler(new DefaultHandler());
		XmlConfiguration configuration = null;
//		try {
			InputStream ins = JettyServer.class.getResourceAsStream("/etc/jetty.xml");
			byte[] data = new byte[ins.available()];
			ins.read(data);
			
			String jetty = new String(data,"ISO-8859-1");
			System.out.println("jetty:"+jetty);
			System.out.println("sssex.Activator.plugin_path:"+sssex.Activator.plugin_path);
			jetty = jetty.replace("{VarPath}", sssex.Activator.plugin_path.replaceFirst("/", ""));
			// System.out.println("jetty:"+jetty);
			configuration = new XmlConfiguration(jetty);
//		} catch (FileNotFoundException e1) {
//			e1.printStackTrace();
//		} catch (SAXException e1) {
//			e1.printStackTrace();
//		} catch (IOException e1) {
//			e1.printStackTrace();
//		}
//		try {
			configuration.configure(server);
			server.start();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
    	} catch (Exception e) {
			e.printStackTrace();
		}
    }
	public static void main(String[] args) {
		start();
	}
}